<?php

class IndexController extends AppController {

    public function index() {
        $slideshow = SlideshowModel::build()->query();

        $categories = CategoryModel::build()
                        ->where(array('homepage' => 1))
                        ->query();

        foreach($categories as &$category) {
            $category->breadcrumbs = CategoryModel::breadcrumbs($category->id);
            $category->products = ProductModel::build()
                                    ->where(array('category_id' => $category->id))
                                    ->order('RAND()')
                                    ->limit(3)
                                    ->page(1)
                                    ->query();
        }

        $this->set(compact('slideshow', 'categories'));
    }

    public function language($lang) {
        $referer = @$_SERVER['HTTP_REFERER'];
        Locale::set($lang);
        $this->redirect(isset($referer) ? $referer : '/');
    }

}


?>